import React, { Component } from 'react';
import { View, StyleSheet, Alert, Keyboard } from 'react-native';
import { GLOBAL } from '../../../../config/global';
import RadioButton from '../../../../components/form/radioButton';
const scale = GLOBAL.SCALE;
export class RadiusGroupCpt extends Component {
	constructor(props) {
		super(props);
		let { selectedKey } = this.props.data || {};
		this.state = {
			selectedKey
		}
	}

	componentWillReceiveProps (props) {
		let { selectedKey } = props.data || {};
		this.setState({
			selectedKey
		})
	}


	render () {
		let { listData, _radiusItemFn, id, radioBox, type, textStyleBox, radioStyle, goodsData, lsData, disable } = this.props.data || {};
		let { selectedKey } = this.state;
		return (
			<View style={[styles.radioBox, radioBox || null, disable ? styles.disableStyle : null]}>
				<View style={[styles.radioView, radioStyle || null]}>
					{
						listData && listData.map((item, index) => {
							return (
								<RadioButton key={index}
									radioValue={item.dictName}
									disable={disable || false}
									radioKey={item.dictKey}
									buttonStyle={styles.buttonStyle}
									selectedKey={selectedKey}
									type={type}
									textStyleBox={textStyleBox}
									selectedChange={(key, value) => {
										Keyboard.dismiss();
										//业务类型
										if (id == 'isUnite' && goodsData && goodsData.length) {  // 
											Alert.alert('提示', `切换业务类型商品将清空`, [
												{
													text: '确认', onPress: () => {
														this.setState({
															selectedKey: key
														}, () => {
															_radiusItemFn && _radiusItemFn(key, id, index, 'clearGoods', lsData)
														})
													}
												},
												{
													text: '取消', onPress: () => {
														console.log('	取消')
													}
												},
											]);
										} else {
											this.setState({
												selectedKey: key
											}, () => {
												_radiusItemFn && _radiusItemFn(key, id, index, type, lsData)
											})
										}

									}} />
							)
						})
					}
				</View>
			</View>
		)
	}
}

const styles = StyleSheet.create({
	radioBox: {
		flexDirection: 'row',
		marginTop: 20 * scale,
		width: '100%'
	},
	radioView: {
		flexDirection: 'row',
		alignItems: 'center',
		flexWrap: 'wrap'
	},
	buttonStyle: {
		width: 90 * scale,
		marginRight: 0 * scale,
	},
	required: {
		fontSize: 14 * scale,
		color: '#D0021B'
	},
	disableStyle: {
		opacity: .5
	}
})